<template>
	<view class="content mainpadding">
		<!-- 騎手評價 -->
		<view class="mainpadding border ffffff" v-if="qs_ishow">
			<view class="flexleft">
				<view class="text_x color_ling margin_right1">騎手評價</view>
				<u-rate active-color="#FAB536" inactive-color="#b2b2b2" v-model="q_pf" :minCount="1" size="25"></u-rate>
			</view>
			<textarea class="margin_top textareas text_five" placeholder-style="font-size: 26rpx;color: #999999;"
				cols="30" rows="10" placeholder="請輸入您的評價" v-model="q_txt"></textarea>
		</view>
		<!-- 店鋪評價 -->
		<view class="mainpadding border ffffff margin_top">
			<template v-if="type!=2">
				<view class="flexleft">
					<view class="text_x color_ling margin_right1">店鋪評價</view>
					<u-rate active-color="#FAB536" inactive-color="#b2b2b2" v-model="shop_pf" :minCount="1" size="25"></u-rate>
				</view>
				<textarea class="margin_top textareas text_five" placeholder-style="font-size: 26rpx;color: #999999;"
					cols="30" rows="10" placeholder="請輸入您的評價" v-model="shop_txt"></textarea>
				<!-- 圖片 -->
				<view class="flexleft flex_wrap">
					<view class="item_image_box margin_top" v-for="(item,index) in images_text" :key="index">
						<view class="item_image radius">
							<image :src="item" mode=""></image>
							<view class="deletimg" @click="deleimage(index,images,images_text)"></view>
						</view>
					</view>
					<!-- 圖片盒子 -->
					<view class="item_image_box margin_top" @click="uploadImg(3,images,images_text)" v-if="images.length<3">
						<view class="item_image radius">
							<image src="/static/images/mine/noImage.png" mode=""></image>
						</view>
					</view>
				</view>
			</template>
			<!-- 是否匿名評價 -->
			<view class="flexbetween margin_top">
				<view class="text_x color_san">匿名評價</view>
				<u-switch inactiveColor="rgb(230, 230, 230)" v-model="value" activeColor="#FFB800"></u-switch>
			</view>
		</view>
		<view class="footer">
			<view class="footerButton" @click="submit">發表</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				type: 1, //1商品訂單，2跑腿訂單，3呼叫訂單，4預約訂單，5票券
				qs_ishow: false,
				listid: "",
				images: [],
				images_text: [],
				q_pf:1,
				q_txt:"",
				shop_pf:1,
				shop_txt:"",
				value: false,
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg))
			this.type = data.type
			this.qs_ishow = data.qs_ishow
			this.listid = data.id
			console.log(data,"界面接收参數");
		},
		methods: {
			submit() {
				let url= "/api/ordergoods/addevaluate"
				if(this.qs_ishow){
					if(this.q_txt==""){
						this.http.toast("請輸入騎手評價！")
						return false
					}
				}
				if(this.type!=2){
					if(this.shop_txt==""){
						this.http.toast("請輸入店鋪評價！")
						return false
					}
				}
				let obj = {
					"1":1,//商品訂單
					"2":3,//跑腿
					"3":2,//呼叫訂單
				}
				let data = {
					type:obj[this.type],
					order_id:this.listid,
					q_pf:this.q_pf,
					q_txt:this.q_txt,
					shop_pf:this.shop_pf,
					images:this.images.join(),
					shop_txt:this.shop_txt,
					is_n:this.value,
				}
				if(this.type==2){
					delete data.shop_pf
					delete data.images
					delete data.shop_txt
				}
				this.http.request(url, 'POST', data).then(res => {
					this.http.toast(res.msg)
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					}
				})

			},
			uploadImg(value, upImgs, upImgs_text) { //上傳圖片
				let _this = this;
				let num = Number(value) - upImgs.length;
				if (num <= 0) {
					return false;
				}
				uni.showActionSheet({
					itemList: ['照機', '相簿'],
					success: function(res) {
						// 選擇照機走0
						if (res.tapIndex == 0) {
							_this.http.chooseImage(num, ['camera']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
						// 選擇相簿走1
						if (res.tapIndex == 1) {
							_this.http.chooseImage(num, ['album']).then(res => {
								for (var i = 0; i < res.length; i++) {
									_this.uploadImageService(res[i], upImgs, upImgs_text)
								}
							}).catch(err => {});
						}
					},
					fail: function(res) {}
				});
			},
			delindex(index, upImg, upImgs_text) {
				upImg.splice(index, 1)
				upImgs_text.splice(index, 1)
			},
			uploadImageService(url, upImg, upImgs_text) {
				let _this = this;
				this.http.uploadFile('/api/common/upload', url).then(res => {
					let image_item = res.fullurl;
					upImg.push(res.url)
					upImgs_text.push(image_item);
				}).catch(err => {});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.textareas {
		width: 100%;
		box-sizing: border-box;
		height: 203rpx;
		padding: 30rpx;
		border-radius: 8rpx;
		border: 2rpx solid #EFEFEF;
	}
</style>